<?php

class View_Helper_MenuHelper extends Model3_View_Helper {

    private $_cr;
    
    public function display() 
    {
        if (Model3_Auth::isAuth()) 
        {
            $this->_cr = Model3_Auth::getCredentials();
            $dbs = Model3_Registry::getInstance()->get('databases');
            $em = $dbs['DefaultDb'];
            $user = $em->find('DefaultDb_Entities_User', $this->_cr['id']);
            switch ($this->_cr['type']) 
            {
                case DefaultDb_Entities_User::USER_ADMIN :
                        $this->displayMenuAdmin();
                    break;
                case DefaultDb_Entities_User::USER_DRIVER:
                        $this->displayMenuDriver();
                    break;
                case DefaultDb_Entities_User::USER_CLIENT:
                        $this->displayMenuClient();
                    break;
                default:
                        Model3_Auth::deleteCredentials();
                        $this->displayMenuNone();
                    break;
            }
        } 
        else 
        {
            $this->displayMenuNone();
        }
    }

    private function printLogOut($cr) 
    {
    ?>
        <ul class="nav pull-right">
            <li><a>Usuario: <?php echo $cr['username']; ?></a></li>
            <li><a href="#" title="cerrar sesion" id="sessionExit"><i class="icon-off icon-white" ></i> Salir</a></li>
        </ul>
    <?php
    }

    private function displayMenuAdmin()
    {
    ?>
        <div class="navbar">
            <div class="navbar-inner">
                <div class="container">
                    <div class="nav-collapse">
                        <ul class="nav">
                            <li><a href="<?php echo $this->_view->url(array('module' => 'Admin', 'controller' => 'Dashboard', 'action' => 'index')) ?>" ><?php echo ($this->_view->TrHelper()->_('Inicio')); ?></a> </li>
                            <li class="dropdown">
                                <a href="#" class="dropdown-toggle" data-toggle="dropdown"><?php echo $this->_view->TrHelper()->_('Tiendas'); ?> <b class="caret"></b></a>
                                <ul class="dropdown-menu">
                                    <!--<li><a href="<?php // echo $this->_view->url(array('module' => 'Admin', 'controller' => 'PackagesTypes', 'action' => 'index')) ?>" ><?php // echo $this->_view->TrHelper()->_('Paquetes'); ?></a></li>-->
                                    <li><a href="<?php echo $this->_view->url(array('module' => 'Admin', 'controller' => 'Categories', 'action' => 'index')) ?>" ><?php echo $this->_view->TrHelper()->_('Categorias'); ?></a></li>
                                    <li class="divider"></li>
                                    <li><a href="<?php echo $this->_view->url(array('module' => 'Admin', 'controller' => 'Reports', 'action' => 'orders')) ?>" ><?php echo $this->_view->TrHelper()->_('Ordenes'); ?></a></li>
                                </ul>
                            </li>
                            <li class="dropdown">
                                <a href="#" class="dropdown-toggle" data-toggle="dropdown"><?php echo $this->_view->TrHelper()->_('Rutas'); ?><b class="caret"></b></a>
                                <ul class="dropdown-menu">
                                    <li><a href="<?php echo $this->_view->url(array('module' => 'Admin', 'controller' => 'Routes', 'action' => 'index')) ?>" ><?php echo $this->_view->TrHelper()->_('Rutas'); ?></a></li>
                                    <li><a href="<?php echo $this->_view->url(array('module' => 'Admin', 'controller' => 'Calendar', 'action' => 'index')) ?>" ><?php echo $this->_view->TrHelper()->_('Calendario'); ?></a></li>
                                    <li><a href="<?php echo $this->_view->url(array('module' => 'Admin', 'controller' => 'Program', 'action' => 'index')) ?>" ><?php echo $this->_view->TrHelper()->_('Programación'); ?></a></li>
                                    <li class="divider"></li>
                                    <li><a href="<?php echo $this->_view->url(array('module' => 'Admin', 'controller' => 'Reports', 'action' => 'secuencialActivity')) ?>" ><?php echo $this->_view->TrHelper()->_('Reporte de Actividades'); ?></a></li>
                                </ul>
                            </li>
                            <li class="dropdown">
                                <a href="#" class="dropdown-toggle" data-toggle="dropdown"><?php echo $this->_view->TrHelper()->_('Sistema'); ?><b class="caret"></b></a>
                                <ul class="dropdown-menu">
                                    <li><a href="<?php echo $this->_view->url(array('module' => 'Admin', 'controller' => 'Vehicles', 'action' => 'index')) ?>" ><?php echo $this->_view->TrHelper()->_('Vehículos'); ?></a></li>
                                    <li><a href="<?php echo $this->_view->url(array('module' => 'Admin', 'controller' => 'AdminUsers', 'action' => 'index')) ?>" ><?php echo $this->_view->TrHelper()->_('Usuarios'); ?></a></li>
                                    <li><a href="<?php echo $this->_view->url(array('module' => 'Admin', 'controller' => 'InvoicesUsers', 'action' => 'index')) ?>" ><?php echo $this->_view->TrHelper()->_('Facturacion'); ?></a></li>
                                    <li><a href="<?php echo $this->_view->url(array('module' => 'Admin', 'controller' => 'Email', 'action' => 'index')) ?>" ><?php echo $this->_view->TrHelper()->_('Correos'); ?></a></li>
                                    <li><a href="<?php echo $this->_view->url(array('module' => 'Admin', 'controller' => 'ConfigSystem', 'action' => 'index')) ?>" ><?php echo $this->_view->TrHelper()->_('Configuracion'); ?></a></li>
                                </ul>
                            </li>
                        </ul>
                        <?php $this->printLogOut($this->_cr);?>
                    </div>
                </div>
            </div>
        </div>
    <?php
    }
    
    private function displayMenuClient()
    {
    ?>
        <div class="navbar">
            <div class="navbar-inner">
                <div class="container">
                    <div class="nav-collapse">
                        <ul class="nav">
                            <li><a href="<?php echo $this->_view->url(array('module' => 'User', 'controller' => 'Dashboard', 'action' => 'index')) ?>" ><i class="icon-home icon-white"></i><?php echo ($this->_view->TrHelper()->_('Inicio')); ?></a> </li>
                            <li class="dropdown">
                                <a href="#" class="dropdown-toggle" data-toggle="dropdown"><i class="icon-th-list icon-white"></i><?php echo $this->_view->TrHelper()->_('Mi panel'); ?> <b class="caret"></b></a>
                                <ul class="dropdown-menu">
                                    <li><a href="<?php echo $this->_view->url(array('module' => 'User', 'controller' => 'Catalogos', 'action' => 'index')) ?>" ><i class="icon-book"></i><?php echo $this->_view->TrHelper()->_('Catalogos'); ?></a></li>
                                    <li><a href="<?php echo $this->_view->url(array('module' => 'User', 'controller' => 'InvoicesUsers', 'action' => 'index')) ?>" ><i class="icon-book"></i><?php echo $this->_view->TrHelper()->_('Facturacion'); ?></a></li>
                                    <li><a href="<?php echo $this->_view->url(array('module' => 'User', 'controller' => 'BackStore', 'action' => 'orders')) ?>" ><i class="icon-folder-close"></i><?php echo $this->_view->TrHelper()->_('Ventas'); ?></a></li>
                                    <li><a href="<?php echo $this->_view->url(array('module' => 'User', 'controller' => 'BackStore', 'action' => 'shopping')) ?>" ><i class="icon-lock"></i><?php echo $this->_view->TrHelper()->_('Compras'); ?></a></li>
                                    <li><a href="<?php echo $this->_view->url(array('module' => 'User', 'controller' => 'BranchesUser', 'action' => 'index')) ?>" ><i class="icon-lock"></i><?php echo $this->_view->TrHelper()->_('Sucursales'); ?></a></li>
                                    <li class="divider"></li>

                                </ul>
                            </li>
                            <li><a href="<?php echo $this->_view->url(array('module' => 'User', 'controller' => 'Store', 'action' => 'index')) ?>" ><i class="icon-tags icon-white"></i><?php echo $this->_view->TrHelper()->_('Tiendas'); ?></a></li>
                            <li><a href="<?php echo $this->_view->url(array('module' => 'User', 'controller' => 'Store', 'action' => 'viewCart')) ?>" ><i class="icon-shopping-cart icon-white"></i><?php echo $this->_view->TrHelper()->_('Carrito'); ?></a></li>
                            <li><a href="<?php echo $this->_view->url(array('module' => 'User', 'controller' => 'FavoriteUsers', 'action' => 'index')) ?>" ><i class="icon-star icon-white"></i><?php echo $this->_view->TrHelper()->_('Favoritos'); ?></a></li>
                            <li class="dropdown">
                                <a href="#" class="dropdown-toggle" data-toggle="dropdown"><?php echo $this->_view->TrHelper()->_($this->_cr['username']); ?><b class="caret"></b></a>
                                <ul class="dropdown-menu" nav pull-right>
                                    <li><a href="<?php echo $this->_view->url(array('module' => 'User', 'controller' => 'UserProfile', 'action' => 'index')) ?>" ><?php echo $this->_view->TrHelper()->_('Datos Personales'); ?></a></li>
                                    <li><a href="<?php echo $this->_view->url(array('module' => 'User', 'controller' => 'UserProfile', 'action' => 'password')) ?>" ><?php echo $this->_view->TrHelper()->_('Passsword'); ?></a></li>
                                    <li><a href="#" id="sessionExit"><?php echo $this->_view->TrHelper()->_('Salir') ;?></a></li>
                                </ul>
                            </li>
                        </ul>
                    </div>
                </div>
            </div>
        </div>
    <?php
    }
    
    private function displayMenuDriver()
    {
    ?>
        <div class="navbar">
            <div class="navbar-inner">
                <div class="container">
                    <div class="nav-collapse">
                        <ul class="nav">
                            <li><a href="<?php echo $this->_view->url(array('module' => 'Driver', 'controller' => 'Dashboard', 'action' => 'index')) ?>" ><?php echo ($this->_view->TrHelper()->_('Inicio')); ?></a> </li>
                        </ul>
                        <?php $this->printLogOut($this->_cr);?>
                    </div>
                </div>
            </div>
        </div>
    <?php
    }
    private function displayMenuNone()
    {
        ?>
        <div class="navbar ">
                <div class="navbar-inner">
                    <div class="container">
                        <ul class="nav">
                            <li><a href="<?php echo $this->_view->url(array('module' => false, 'controller' => 'Index', 'action' => 'index')) ?>" ><?php echo ($this->_view->TrHelper()->_('Inicio')); ?></a> </li>
                        </ul>
                    </div>
                </div>
            </div>
        <?php
    }
}
